package com.weichuanbo.xwdz.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.widget.DrawerLayout;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.weichuanbo.xwdz.R;
import com.weichuanbo.xwdz.app.Common;
import com.weichuanbo.xwdz.app.utils.SaveBeanUtil;
import com.weichuanbo.xwdz.app.widget.NoScrollViewPager;
import com.weichuanbo.xwdz.app.widget.TextProgress;
import com.weichuanbo.xwdz.di.component.DaggerMainComponent;
import com.weichuanbo.xwdz.di.module.MainModule;
import com.weichuanbo.xwdz.mvp.contract.MainContract;
import com.weichuanbo.xwdz.mvp.model.entity.UserBean;
import com.weichuanbo.xwdz.mvp.presenter.MainPresenter;
import com.weichuanbo.xwdz.mvp.ui.fragment.GameHomeFragment;

import butterknife.BindView;
import butterknife.OnClick;
import static com.jess.arms.utils.Preconditions.checkNotNull;


public class MainActivity extends BaseActivity<MainPresenter> implements MainContract.View {

    @BindView(R.id.vp_home_pager)
    NoScrollViewPager vpHomePager;
    @BindView(R.id.iv_game)
    ImageView ivGame;
    @BindView(R.id.rl_game)
    RelativeLayout rlGame;
    @BindView(R.id.rl_heart_match)
    RelativeLayout rlHeartMatch;
    @BindView(R.id.iv_im)
    ImageView ivFriend;
    @BindView(R.id.tv_unread)
    TextView tvUnread;
    @BindView(R.id.rl_friend)
    RelativeLayout rlFriend;
    @BindView(R.id.ll_navigation)
    LinearLayout llNavigation;
    @BindView(R.id.rl_main_bottom_navigation)
    RelativeLayout rlMainBottomNavigation;
    @BindView(R.id.user_avatar_view)
    ImageView userAvatarView;
    @BindView(R.id.tv_lv)
    TextView tvLv;
    @BindView(R.id.tv_my_name)
    TextView tvMyName;
    @BindView(R.id.pgsBar)
    TextProgress pgsBar;
    @BindView(R.id.tv_progress)
    TextView tvProgress;
    @BindView(R.id.ll_head_view)
    LinearLayout llHeadView;
    @BindView(R.id.tv_mibi)
    TextView tvMibi;
    @BindView(R.id.tv_gold)
    TextView tvGold;
    @BindView(R.id.tv_gxt)
    TextView tvGxt;
    @BindView(R.id.ll_property)
    LinearLayout llProperty;
    @BindView(R.id.tv_shop)
    TextView tvShop;
    @BindView(R.id.tv_setting)
    TextView tvSetting;
    @BindView(R.id.tv_preview)
    TextView tvPreview;
    @BindView(R.id.header_container)
    RelativeLayout headerContainer;
    @BindView(R.id.ll_drawerLayout)
    RelativeLayout llDrawerLayout;
    @BindView(R.id.drawer_layout)
    DrawerLayout drawerLayout;
    private UserBean mUserInfo;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerMainComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .mainModule(new MainModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_main; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        mUserInfo = (UserBean) SaveBeanUtil.getBean(this, Common.Const.VIPINFO);
        initViewPage();
    }

    private void initViewPage() {
        vpHomePager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                if (position == 0) {
                    GameHomeFragment  gameHomeFragment = new GameHomeFragment();
                    return gameHomeFragment;//游戏大厅页面
                } else {
                    GameHomeFragment    messageFragment = new GameHomeFragment();
                    return messageFragment;//聊天页面
                }
            }

            @Override
            public int getCount() {
                return 2;
            }
        });
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @OnClick({R.id.rl_game, R.id.rl_friend, R.id.user_avatar_view,
            R.id.tv_mibi, R.id.tv_gold, R.id.tv_gxt, R.id.tv_shop,
            R.id.tv_setting, R.id.rl_heart_match, R.id.ll_head_view, R.id.tv_preview})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_game:
                vpHomePager.setCurrentItem(0);
                ivGame.setImageResource(R.mipmap.icon_game_green);
                ivFriend.setImageResource(R.mipmap.icon_news_gray);
                break;
            case R.id.rl_friend:
                vpHomePager.setCurrentItem(1);
                ivGame.setImageResource(R.mipmap.icon_game_gray);
                ivFriend.setImageResource(R.mipmap.icon_news_green);
                break;
            //点击头像
            case R.id.user_avatar_view:
               /* if (mUserInfo != null) {
                    startActivity(new Intent(MainActivity.this, UserDetailActivity.class).putExtra("friend", mUserInfo.getAccount())
                            .putExtra("status", "1"));
                }*/
                break;
            //点击侧边栏上半部分
            case R.id.ll_head_view:
//                if (mUserInfo != null) {
//                    startActivity(new Intent(MainActivity.this, UserDetailActivity.class).putExtra("friend", mUserInfo.getAccount())
//                            .putExtra("status", "1"));
//                }
                break;
            //心动匹配
            case R.id.rl_heart_match:
//                startActivity(new Intent(this, HeadMatchingActivity.class));
//                overridePendingTransition(R.anim.push_bottom_in, R.anim.activity_stay);
                break;
            case R.id.tv_mibi:
                break;
            case R.id.tv_gold:
                break;
            case R.id.tv_gxt:
                break;
            //商城
            case R.id.tv_shop:
                break;
            //设置
            case R.id.tv_setting:
//                startActivity(new Intent(MainActivity.this, SettingActivity.class));
                break;
            //下版预告
            case R.id.tv_preview:
//                startActivity(new Intent(this, PreviewActivity.class));
                break;
        }

    }
}